import Fleeing
import Depositing
import Mining

# **
# *  'SM_MINER' handles influence imposed by the World through
# *  its Owner (self.ship) and responds accordingly, usually instigating 
# *  state transitions through influence parameters, specified in the Legend (Below).
# *  
# *
# * PUBLIC FEATURES:
# *    // Constructors
# *    def __init__(self, ship)
# *
# *    // Methods
# *    def changeState(self,state)
# *    def handleMessage(self, msg, telegram)
# *    def revertToPreviousState(self)
# *    def update(self, msg, time):
# *
# *    COLLABORATORS:
# *    Fleeing
# *    Depositing
# *    Mining
# *
# * MODIFIED:
# * @version 1.1, 2007-05-24
# * @author Julian Andreou 5422329
# * @author Gavan Hunter 5422264
# * @author  Simon Iskra 5422361
# * @author  Joel Schmidt 2660660 
# */

#**Influence Legend
#
#    0:    Fleeing      *Change State*
#    1:    Depositing   *Change State*
#    2:    Mining       *Change State*


class SM_MINER():
    def __init__(self, ship): 
        self.currentState = Mining.Mining()
        self.previousState = Mining.Mining()
        self.ship = ship
        
    
    def changeState(self, state):
        self.previousState = self.currentState
    
        self.currentState.Exit(self.ship)
        
        
        self.currentState = state
        
        self.currentState.Enter(self.ship)
    

    def revertToPreviousState(self):
        self.changeState(self.previousState)

    def update(self):
        if self.currentState.stateString == "Mining":
            if self.ship.minerals >= self.ship.MAX_Minerals:
                self.changeState(Depositing.Depositing())
        if self.currentState.stateString == "Depositing":
            if self.ship.minerals == 0:
                self.changeState(Mining.Mining())
        self.currentState.Execute(self.ship)
        
    